#!/usr/bin/env bash

REPO_SERVER=192.168.20.160
TOOLS_DIR=/home/lavenliu/tools/
APP_DIR=/application/

# 安装PHP依赖包
yum --enablerepo=lanrepo --disablerepo=base,extras,updates,epel install -y libpng-devel libjpeg-devel libtiff-devel libxml2-devel
yum --enablerepo=lanrepo --disablerepo=base,extras,updates,epel install -y freetype-devel gd-devel curl-devel
yum --enablerepo=lanrepo --disablerepo=base,extras,updates,epel install -y libmcrypt-devel mhash-devel mhash libxslt-devel libtool-ltdl-devel

# 安装特殊功能软件libiconv
cd ${TOOLS_DIR}
wget http://${REPO_SERVER}/tools/libiconv-1.14.tar.gz
tar -xf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
make install

cd ${TOOLS_DIR} 
wget http://${REPO_SERVER}/tools/php-5.3.27.tar.gz
tar -xf php-5.3.27.tar.gz
cd php-5.3.27
./configure --prefix=/application/php-5.3.27 \
--with-mysql=/application/mysql \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-ftp
make
if [ ! -e ext/phar/phar.phar ] ; then
	touch ext/phar/phar.phar
fi
make install
ln -s ${APP_DIR}/php-5.3.27 ${APP_DIR}/php

# 设置PHP配置文件
cp ${TOOLS_DIR}/php-5.3.27/php.ini-production ${APP_DIR}/php/lib/php.ini
cp ${APP_DIR}/php/etc/php-fpm.conf.default ${APP_DIR}/php/etc/php-fpm.conf

/application/php/sbin/php-fpm
